﻿namespace AuthorityManagement.Helper
{
    public class RuturnHelper
    {
        public class AjaxResult
        {
            /// <summary>
            /// 操作结果类型
            /// </summary>
            public object state { get; set; }
            /// <summary>
            /// 获取 消息内容
            /// </summary>
            public string message { get; set; }
            /// <summary>
            /// 获取 返回数据
            /// </summary>
            public object data { get; set; }
        }

        public enum ResultType
        {
            /// <summary>
            /// 消息结果类型
            /// </summary>
            info,
            /// <summary>
            /// 成功结果类型
            /// </summary>
            success,
            /// <summary>
            /// 警告结果类型
            /// </summary>
            warning,
            /// <summary>
            /// 异常结果类型
            /// </summary>
            error,
            /// <summary>
            /// 再次确认
            /// </summary>
            confirm,
            /// <summary>
            /// 跳转
            /// </summary>
            jump
        }

        public class RR
        {
            /// <summary>
            /// 成功
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <returns></returns>
            public static string Success(string message)
            {
                return new AjaxResult { state = ResultType.success.ToString(), message = message }.ToJson();
            }
            /// <summary>
            /// 成功
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <param name="data">返回结果数据</param>
            /// <returns></returns>
            public static string Success(string message, object data)
            {
                return new AjaxResult { state = ResultType.success.ToString(), message = message, data = data }.ToJson();
            }
            /// <summary>
            /// 失败，错误
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <returns></returns>
            public static string Error(string message)
            {
                return new AjaxResult { state = ResultType.error.ToString(), message = message }.ToJson();
            }

            /// <summary>
            /// 失败，错误
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <param name="data">返回结果数据</param>
            /// <returns></returns>
            public static string Error(string message, object data)
            {
                return new AjaxResult { state = ResultType.error.ToString(), message = message, data = data }.ToJson();
            }
            /// <summary>
            /// 消息
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <returns></returns>
            public static string Info(string message)
            {
                return new AjaxResult { state = ResultType.info.ToString(), message = message }.ToJson();
            }
            /// <summary>
            /// 消息
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <param name="data">返回结果数据</param>
            /// <returns></returns>
            public static string Info(string message, object data)
            {
                return new AjaxResult { state = ResultType.info.ToString(), message = message, data = data }.ToJson();
            }
            /// <summary>
            /// 消息
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <returns></returns>
            public static string Jump(string message)
            {
                return new AjaxResult { state = ResultType.jump.ToString(), message = message }.ToJson();
            }
            /// <summary>
            /// 消息
            /// </summary>
            /// <param name="message">返回结果描述</param>
            /// <param name="data">返回结果数据</param>
            /// <returns></returns>
            public static string Jump(string message, object data)
            {
                return new AjaxResult { state = ResultType.jump.ToString(), message = message, data = data }.ToJson();
            }
            /// <summary>
            /// 列表
            /// </summary>
            /// <param name="totalNumber">数据总数</param>
            /// <param name="data">返回结果数据</param>
            /// <returns></returns>
            public static string ListResult(int totalNumber, object data)
            {
                return "{ \"count\": " + totalNumber.ToString() + ", \"data\":" + data.ToJson() + "}";
            }

            /// <summary>
            /// 列表
            /// </summary>
            /// <param name="totalNumber">数据总数</param>
            /// <param name="data">返回结果数据</param>
            /// <param name="dateTimeFormat">时间格式</param>
            /// <returns></returns>
            public static string ListResult(int totalNumber, object data, string dateTimeFormat)
            {
                return "{ \"count\": " + totalNumber.ToString() + ", \"data\":" + data.ToJson(dateTimeFormat) + "}";
            }
            /// <summary>
            /// 列表(空)
            /// </summary>
            /// <returns></returns>
            public static string ListResult()
            {
                return "{ \"count\": 0, \"data\":[]}";
            }
        }
    }
}
